__author__ = 'x0r'

import ConfigParser

class Settings:
    def __init__(self,conf):
        """
        Default constructor
        """
        self.syncInterval = 0
        self.sendInterval = 0

        # Public member
        self.value = dict()

        self._conf = '/home/x0r/work/goodmon/magentd/magentd.conf'
        print "Config file: ", self._conf
        self.cp = ConfigParser.RawConfigParser(allow_no_value=True)
        self.cp.read(self._conf)
        self.readConf()


    def readConf(self):
        """
        Read all values from config file to dictionary.
        """
        self.value = dict(
            syncInterval    =   self.cp.get('main','syncInterval'),
            sendInterval    =   self.cp.get('main','sendInterval'),
            agentID         =   self.cp.get('main','agentID'),
            remoteHost      =   self.cp.get('main','remoteHost'),
            remotePort      =   self.cp.get('main','remotePort'),
            log             =   self.cp.get('main','log'),
            firstStart      =   self.cp.get('main','firstStart')
        )


    def set(self,option,value):
        self.cp.set("main",option,value)
        with open(self._conf, 'wb') as configfile:
            self.cp.write(configfile)